fix(session): strip reasoning blocks for Claude Code compatibility#7035
fix(session): strip reasoning blocks for Claude Code compatibility#7035romancircus wants to merge 1 commit intoanomalyco:devfrom
Conversation
When switching from a reasoning model (like Claude with extended thinking) to Claude Code, the message history contained reasoning blocks that Claude Code's API doesn't recognize, causing 'Invalid signature' errors. Filter out reasoning parts from messages before converting to model format, allowing seamless switching between reasoning and non-reasoning models.
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs Found:
Recommendation: PR #6748 appears to be the most closely related - it may have already implemented a solution for a similar issue with thinking/reasoning blocks. You should check if that PR's approach can be unified with your fix, or if they should be consolidated. |
|
Thanks for the quick feedback @rekram1-node! You're absolutely right - stripping reasoning blocks unconditionally would break stateful reasoning models that need these blocks sent back during the conversation loop. I see PR #6748 addresses this more correctly at the provider transform layer. I'll close this PR and defer to that approach. Appreciate the review! |

Summary
Strip reasoning blocks from message history when converting to model format, enabling seamless switching between reasoning and non-reasoning models.
Problem
When using a reasoning model (e.g., Claude with extended thinking) and then switching to Claude Code, the session fails with an "Invalid signature" error. This happens because Claude Code's API doesn't recognize the reasoning blocks that were added by the previous model.
Solution
Filter out
reasoningtype parts from messages inconvertToModelMessages()before sending to the model API. This ensures compatibility regardless of which models were used earlier in the session.Changes
packages/opencode/src/session/message-v2.ts- Filter reasoning parts in message conversionTesting